package br.unb.graphics.actions;

import br.unb.core.dispatcher.TrafficDispatcher;
import br.unb.graphics.GraphicInterface;
import br.unb.utils.Console;
import br.unb.utils.LogFile;
import br.unb.utils.Path;
import br.unb.utils.Resource;
import java.awt.event.ActionEvent;
import java.io.File;
import javax.swing.AbstractAction;
import javax.swing.JFileChooser;

/**
 *
 * @author spider
 */
public class OpenQosAction extends AbstractAction {

    public static final String openQosAction = "openQos";

    public OpenQosAction() {
        super(openQosAction);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        JFileChooser fc = new JFileChooser(Path.getLogDir());
        fc.setFileFilter(LogFile.Type.RECEIVER.getFileFilter());
        fc.setDialogTitle("Open Qos File");

        int o = fc.showOpenDialog(null);
        switch (o) {
            case JFileChooser.APPROVE_OPTION: {
                File qosFile = fc.getSelectedFile();
                File l = new File(qosFile.getName());
                if (qosFile != null) {
                    GraphicInterface.getInstance().showQosPanel();
                    TrafficDispatcher.qosController.loadValuesFromFile(qosFile);
                } else {
                    Console.printError(Resource.getString("SELECT_VALID_FILE"));
                }
            }
            break;
            case JFileChooser.CANCEL_OPTION: {
                Console.printError(Resource.getString("FILE_SELECTION_CANCELED"));
            }
            break;
        }
    }
}


